package com.codeduck.properties.defaultConfig.othersConfig;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * 第二种通过@PropertySource 与 @ConfigurationProperties 获取配置文件所在路径 与 配置文件的前缀
 * 然后通过调用bean的set方法进行value注入
 * 注：需要依赖 {org.springframework.boot.spring-boot-configuration-processor} 包
 *
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @since: 2021-12-22
 */
@Configuration
@ConfigurationProperties(prefix = "config", ignoreInvalidFields = true)
@PropertySource("classpath:config.properties")
public class OthersConfig {

    private String name;

    private Integer age;

    private String fullValue;

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public void setFullValue(String fullValue) {
        this.fullValue = fullValue;
    }

    public String getName() {
        return name;
    }

    public Integer getAge() {
        return age;
    }

    public String getFullValue() {
        return fullValue;
    }

    @Override
    public String toString() {
        return "TestBean{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", fullValue='" + fullValue + '\'' +
                '}';
    }
}
